<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li class="active"><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. 应用场景">1. 应用场景</a></li><li><a href="#t12. 名词">2. 名词</a></li><li><a href="#t23.设计思路">3.设计思路</a></li><li><a href="#t34. 工作流程">4. 工作流程</a></li><li><a href="#t45. 客户端的授权模式">5. 客户端的授权模式</a><ul><li><a href="#t55.1 授权码模式">5.1 授权码模式</a></li><li><a href="#t65.2 简化模式">5.2 简化模式</a></li><li><a href="#t75.3 密码模式">5.3 密码模式</a></li><li><a href="#t85.4 客户端模式">5.4 客户端模式</a></li></ul></li><li><a href="#t96. 接入QQ">6. 接入QQ</a><ul><li><a href="#t106.1 接入流程">6.1 接入流程</a></li><li><a href="#t116.2 QQ开发平台的前置条件">6.2 QQ开发平台的前置条件</a></li><li><a href="#t126.3 安装服务器">6.3 安装服务器</a></li><li><a href="#t136.4 添加应用">6.4 添加应用</a></li><li><a href="#t146.5 编写应用">6.5 编写应用</a><ul><li><a href="#t156.5.1 QQ连接">6.5.1 QQ连接</a></li><li><a href="#t166.5.2 获取数据流程">6.5.2 获取数据流程</a></li></ul></li></ul></li><li><a href="#t177.开发自己的Oauth系统">7.开发自己的Oauth系统</a><ul><li><a href="#t187.1 开发客户端">7.1 开发客户端</a><ul><li><a href="#t197.1.1 config.js">7.1.1 config.js</a></li><li><a href="#t207.1.2 utils.js">7.1.2 utils.js</a></li><li><a href="#t217.1.3 model.js">7.1.3 model.js</a></li><li><a href="#t227.1.4 app.js">7.1.4 app.js</a></li><li><a href="#t237.1.5 user.js">7.1.5 user.js</a></li><li><a href="#t247.1.6 login.html">7.1.6 login.html</a></li><li><a href="#t257.1.7 index.html">7.1.7 index.html</a></li></ul></li><li><a href="#t267.2 开发授权服务器">7.2 开发授权服务器</a><ul><li><a href="#t277.2.1 model.js">7.2.1 model.js</a></li><li><a href="#t287.2.2 mock.js">7.2.2 mock.js</a></li><li><a href="#t297.2.3 app.js">7.2.3 app.js</a></li><li><a href="#t307.2.4 oauth2.js">7.2.4 oauth2.js</a></li><li><a href="#t317.2.5 routes/users.js">7.2.5 routes/users.js</a></li><li><a href="#t327.2.6 authorize.html">7.2.6 authorize.html</a></li></ul></li></ul></li><li><a href="#t338. 参考资料">8. 参考资料</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. &#x5E94;&#x7528;&#x573A;&#x666F;">1. &#x5E94;&#x7528;&#x573A;&#x666F; <a href="#t01. &#x5E94;&#x7528;&#x573A;&#x666F;"> # </a></h2>
<ul>
<li>&#x6BD4;&#x5982;&#x767E;&#x5EA6;&#x5E0C;&#x671B;&#x80FD;&#x83B7;&#x53D6;QQ&#x7528;&#x6237;&#x7684;&#x76F8;&#x518C;</li>
<li>&#x95EE;&#x9898;&#x662F;&#x53EA;&#x6709;&#x5F97;&#x5230;&#x7528;&#x6237;&#x7684;&#x6388;&#x6743;&#xFF0C;QQ&#x624D;&#x4F1A;&#x540C;&#x610F;&#x8BA9;&#x767E;&#x5EA6;&#x8BFB;&#x53D6;&#x8FD9;&#x4E9B;&#x7167;&#x7247;</li>
<li>&#x90A3;&#x4E48;&#xFF0C;&#x6211;&#x4EEC;&#x600E;&#x6837;&#x83B7;&#x5F97;&#x7528;&#x6237;&#x7684;&#x6388;&#x6743;&#x5462;&#xFF1F;</li>
</ul>
<p>&#x4F20;&#x7EDF;&#x65B9;&#x6CD5;&#x662F;&#xFF0C;QQ&#x7528;&#x6237;&#x5C06;&#x81EA;&#x5DF1;&#x7684;QQ&#x53F7;&#x548C;&#x5BC6;&#x7801;&#xFF0C;&#x544A;&#x8BC9;&#x767E;&#x5EA6;&#xFF0C;&#x540E;&#x8005;&#x5C31;&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#x7528;&#x6237;&#x7684;&#x76F8;&#x518C;&#x4E86;&#x3002;&#x8FD9;&#x6837;&#x7684;&#x505A;&#x6CD5;&#x6709;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x4E25;&#x91CD;&#x7684;&#x7F3A;&#x70B9;</p>
<ol>
<li>&#x767E;&#x5EA6;&#x4E3A;&#x4E86;&#x540E;&#x7EED;&#x7684;&#x670D;&#x52A1;&#xFF0C;&#x4F1A;&#x4FDD;&#x5B58;&#x7528;&#x6237;&#x7684;&#x5BC6;&#x7801;&#xFF0C;&#x8FD9;&#x6837;&#x5F88;&#x4E0D;&#x5B89;&#x5168;</li>
<li>&#x767E;&#x5EA6;&#x4E0D;&#x5F97;&#x4E0D;&#x90E8;&#x7F72;&#x5BC6;&#x7801;&#x767B;&#x5F55;&#xFF0C;&#x800C;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#xFF0C;&#x5355;&#x7EAF;&#x7684;&#x5BC6;&#x7801;&#x767B;&#x5F55;&#x5E76;&#x4E0D;&#x5B89;&#x5168;</li>
<li>&#x767E;&#x5EA6;&#x62E5;&#x6709;&#x4E86;&#x83B7;&#x53D6;&#x7528;&#x6237;&#x50A8;&#x5B58;&#x5728;QQ&#x4E0A;&#x6240;&#x6709;&#x8D44;&#x6599;&#x7684;&#x6743;&#x529B;&#xFF0C;&#x7528;&#x6237;&#x6CA1;&#x6CD5;&#x9650;&#x5236;&#x767E;&#x5EA6;&#x83B7;&#x5F97;&#x6388;&#x6743;&#x7684;&#x8303;&#x56F4;&#x548C;&#x6709;&#x6548;&#x671F;</li>
<li>&#x7528;&#x6237;&#x53EA;&#x6709;&#x4FEE;&#x6539;&#x5BC6;&#x7801;&#xFF0C;&#x624D;&#x80FD;&#x6536;&#x56DE;&#x8D4B;&#x4E88;&#x767E;&#x5EA6;&#x7684;&#x6743;&#x529B;&#x3002;&#x4F46;&#x662F;&#x8FD9;&#x6837;&#x505A;&#xFF0C;&#x4F1A;&#x4F7F;&#x5F97;&#x5176;&#x4ED6;&#x6240;&#x6709;&#x83B7;&#x5F97;&#x7528;&#x6237;&#x6388;&#x6743;&#x7684;&#x7B2C;&#x4E09;&#x65B9;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x5168;&#x90E8;&#x5931;&#x6548;</li>
<li>&#x53EA;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x7B2C;&#x4E09;&#x65B9;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x88AB;&#x7834;&#x89E3;&#xFF0C;&#x5C31;&#x4F1A;&#x5BFC;&#x81F4;&#x7528;&#x6237;&#x5BC6;&#x7801;&#x6CC4;&#x6F0F;&#xFF0C;&#x4EE5;&#x53CA;&#x6240;&#x6709;&#x88AB;&#x5BC6;&#x7801;&#x4FDD;&#x62A4;&#x7684;&#x6570;&#x636E;&#x6CC4;&#x6F0F;&#x3002;</li>
</ol>
<blockquote>
<p>OAuth&#x5C31;&#x662F;&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x4E0A;&#x9762;&#x8FD9;&#x4E9B;&#x95EE;&#x9898;&#x800C;&#x8BDE;&#x751F;&#x7684;&#x3002;</p>
</blockquote>
<h2 id="t12. &#x540D;&#x8BCD;">2. &#x540D;&#x8BCD; <a href="#t12. &#x540D;&#x8BCD;"> # </a></h2>
<ol>
<li>client: &#x7B2C;&#x4E09;&#x65B9;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#xFF0C;&#x672C;&#x6587;&#x4E2D;&#x53C8;&#x79F0;&#x5BA2;&#x6237;&#x7AEF;&#xFF0C;&#x5373;&#x4E0A;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#x7684;&quot;&#x767E;&#x5EA6;&quot;</li>
<li>Resource Owner&#xFF1A;&#x8D44;&#x6E90;&#x6240;&#x6709;&#x8005;&#xFF0C;&#x672C;&#x6587;&#x4E2D;&#x53C8;&#x79F0;&quot;QQ&#x7528;&#x6237;&quot;&#xFF08;user&#xFF09;&#x3002;</li>
<li>User Agent&#xFF1A;&#x7528;&#x6237;&#x4EE3;&#x7406;&#xFF0C;&#x672C;&#x6587;&#x4E2D;&#x5C31;&#x662F;&#x6307;&#x6D4F;&#x89C8;&#x5668;&#x3002;</li>
<li>http service: &#x63D0;&#x4F9B;&#x670D;&#x52A1;&#x7684;HTTP&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&#xFF0C; &#x5373;&#x4E0A;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#x7684;&quot;QQ&#x670D;&#x52A1;&#x5668;&quot;</li>
<li>Authorization server&#xFF1A;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5373;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&#x4E13;&#x95E8;&#x7528;&#x6765;&#x5904;&#x7406;&#x8BA4;&#x8BC1;&#x7684;&#x670D;&#x52A1;&#x5668;&#x3002;</li>
<li>Resource server&#xFF1A;&#x8D44;&#x6E90;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5373;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&#x5B58;&#x653E;&#x7528;&#x6237;&#x751F;&#x6210;&#x7684;&#x8D44;&#x6E90;&#x7684;&#x670D;&#x52A1;&#x5668;&#x3002;&#x5B83;&#x4E0E;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x540C;&#x4E00;&#x53F0;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E0D;&#x540C;&#x7684;&#x670D;&#x52A1;&#x5668;&#x3002;</li>
</ol>
<blockquote>
<p>OAuth&#x7684;&#x4F5C;&#x7528;&#x5C31;&#x662F;&#x8BA9;&quot;&#x5BA2;&#x6237;&#x7AEF;&quot;&#x5B89;&#x5168;&#x53EF;&#x63A7;&#x5730;&#x83B7;&#x53D6;&quot;&#x7528;&#x6237;&quot;&#x7684;&#x6388;&#x6743;&#xFF0C;&#x4E0E;&quot;&#x670D;&#x52A1;&#x5546;&#x63D0;&#x4F9B;&#x5546;&quot;&#x8FDB;&#x884C;&#x4E92;&#x52A8;&#x3002;</p>
</blockquote>
<h2 id="t23.&#x8BBE;&#x8BA1;&#x601D;&#x8DEF;">3.&#x8BBE;&#x8BA1;&#x601D;&#x8DEF; <a href="#t23.&#x8BBE;&#x8BA1;&#x601D;&#x8DEF;"> # </a></h2>
<ul>
<li>OAuth&#x5728;&quot;&#x5BA2;&#x6237;&#x7AEF;&quot;&#x4E0E;&quot;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&quot;&#x4E4B;&#x95F4;&#xFF0C;&#x8BBE;&#x7F6E;&#x4E86;&#x4E00;&#x4E2A;&#x6388;&#x6743;&#x5C42;&#xFF08;authorization layer&#xFF09;&#x3002;</li>
<li>&quot;&#x5BA2;&#x6237;&#x7AEF;&quot;&#x4E0D;&#x80FD;&#x76F4;&#x63A5;&#x767B;&#x5F55;&quot;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&quot;&#xFF0C;&#x53EA;&#x80FD;&#x767B;&#x5F55;&#x6388;&#x6743;&#x5C42;&#xFF0C;&#x4EE5;&#x6B64;&#x5C06;&#x7528;&#x6237;&#x4E0E;&#x5BA2;&#x6237;&#x7AEF;&#x533A;&#x5206;&#x5F00;&#x6765;&#x3002;</li>
<li>&quot;&#x5BA2;&#x6237;&#x7AEF;&quot;&#x767B;&#x5F55;&#x6388;&#x6743;&#x5C42;&#x6240;&#x7528;&#x7684;&#x4EE4;&#x724C;&#xFF08;token&#xFF09;&#xFF0C;&#x4E0E;&#x7528;&#x6237;&#x7684;&#x5BC6;&#x7801;&#x4E0D;&#x540C;&#x3002;&#x7528;&#x6237;&#x53EF;&#x4EE5;&#x5728;&#x767B;&#x5F55;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6307;&#x5B9A;&#x6388;&#x6743;&#x5C42;&#x4EE4;&#x724C;&#x7684;&#x6743;&#x9650;&#x8303;&#x56F4;&#x548C;&#x6709;&#x6548;&#x671F;&#x3002;</li>
<li>&quot;&#x5BA2;&#x6237;&#x7AEF;&quot;&#x767B;&#x5F55;&#x6388;&#x6743;&#x5C42;&#x4EE5;&#x540E;&#xFF0C;&quot;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&quot;&#x6839;&#x636E;&#x4EE4;&#x724C;&#x7684;&#x6743;&#x9650;&#x8303;&#x56F4;&#x548C;&#x6709;&#x6548;&#x671F;&#xFF0C;&#x5411;&quot;&#x5BA2;&#x6237;&#x7AEF;&quot;&#x5F00;&#x653E;&#x7528;&#x6237;&#x50A8;&#x5B58;&#x7684;&#x8D44;&#x6599;&#x3002;</li>
</ul>
<h2 id="t34. &#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;">4. &#x5DE5;&#x4F5C;&#x6D41;&#x7A0B; <a href="#t34. &#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;"> # </a></h2>
<p><img src="http://img.zhufengpeixun.cn/oauthflows.png" alt="oauthflows"></p>
<ul>
<li>A &#x7528;&#x6237;&#x6253;&#x5F00;&#x5BA2;&#x6237;&#x7AEF;&#x4EE5;&#x540E;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x8981;&#x6C42;&#x7528;&#x6237;&#x7ED9;&#x4E88;&#x6388;&#x6743;&#x3002;</li>
<li>B &#x7528;&#x6237;&#x540C;&#x610F;&#x7ED9;&#x4E88;&#x5BA2;&#x6237;&#x7AEF;&#x6388;&#x6743;&#x3002;</li>
<li>C &#x5BA2;&#x6237;&#x7AEF;&#x4F7F;&#x7528;&#x4E0A;&#x4E00;&#x6B65;&#x83B7;&#x5F97;&#x7684;&#x6388;&#x6743;&#xFF0C;&#x5411;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x7533;&#x8BF7;&#x4EE4;&#x724C;&#x3002;</li>
<li>D &#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x5BF9;&#x5BA2;&#x6237;&#x7AEF;&#x8FDB;&#x884C;&#x8BA4;&#x8BC1;&#x4EE5;&#x540E;&#xFF0C;&#x786E;&#x8BA4;&#x65E0;&#x8BEF;&#xFF0C;&#x540C;&#x610F;&#x53D1;&#x653E;&#x4EE4;&#x724C;&#x3002;</li>
<li>E &#x5BA2;&#x6237;&#x7AEF;&#x4F7F;&#x7528;&#x4EE4;&#x724C;&#xFF0C;&#x5411;&#x8D44;&#x6E90;&#x670D;&#x52A1;&#x5668;&#x7533;&#x8BF7;&#x83B7;&#x53D6;&#x8D44;&#x6E90;&#x3002;</li>
<li>F &#x8D44;&#x6E90;&#x670D;&#x52A1;&#x5668;&#x786E;&#x8BA4;&#x4EE4;&#x724C;&#x65E0;&#x8BEF;&#xFF0C;&#x540C;&#x610F;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x5F00;&#x653E;&#x8D44;&#x6E90;&#x3002;</li>
</ul>
<h2 id="t45. &#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x6388;&#x6743;&#x6A21;&#x5F0F;">5. &#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x6388;&#x6743;&#x6A21;&#x5F0F; <a href="#t45. &#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x6388;&#x6743;&#x6A21;&#x5F0F;"> # </a></h2>
<ul>
<li>&#x5BA2;&#x6237;&#x7AEF;&#x5FC5;&#x987B;&#x5F97;&#x5230;&#x7528;&#x6237;&#x7684;&#x6388;&#x6743;&#xFF08;authorization grant&#xFF09;&#xFF0C;&#x624D;&#x80FD;&#x83B7;&#x5F97;&#x4EE4;&#x724C;&#xFF08;access token&#xFF09;</li>
<li>OAuth 2.0&#x5B9A;&#x4E49;&#x4E86;&#x56DB;&#x79CD;&#x6388;&#x6743;&#x65B9;&#x5F0F;&#x3002;</li>
</ul>
<h3 id="t55.1 &#x6388;&#x6743;&#x7801;&#x6A21;&#x5F0F;">5.1 &#x6388;&#x6743;&#x7801;&#x6A21;&#x5F0F; <a href="#t55.1 &#x6388;&#x6743;&#x7801;&#x6A21;&#x5F0F;"> # </a></h3>
<ul>
<li>&#x6388;&#x6743;&#x7801;&#x6A21;&#x5F0F;&#xFF08;authorization code&#xFF09;&#x662F;&#x529F;&#x80FD;&#x6700;&#x5B8C;&#x6574;&#x3001;&#x6D41;&#x7A0B;&#x6700;&#x4E25;&#x5BC6;&#x7684;&#x6388;&#x6743;&#x6A21;&#x5F0F;</li>
<li>&#x5B83;&#x7684;&#x7279;&#x70B9;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x540E;&#x53F0;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4E0E;&quot;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&quot;&#x7684;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x8FDB;&#x884C;&#x4E92;&#x52A8;&#x3002;</li>
</ul>
<p><img src="http://img.zhufengpeixun.cn/authorizationcode2.png" alt="authorizationcode2"></p>
<p>&#x5B83;&#x7684;&#x6B65;&#x9AA4;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>A &#x7528;&#x6237;&#x8BBF;&#x95EE;&#x5BA2;&#x6237;&#x7AEF;&#xFF0C;&#x540E;&#x8005;&#x5C06;&#x524D;&#x8005;&#x5BFC;&#x5411;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;</li>
<li>B &#x7528;&#x6237;&#x9009;&#x62E9;&#x662F;&#x5426;&#x7ED9;&#x4E88;&#x5BA2;&#x6237;&#x7AEF;&#x6388;&#x6743;</li>
<li>C &#x5047;&#x8BBE;&#x7528;&#x6237;&#x7ED9;&#x4E88;&#x6388;&#x6743;&#xFF0C;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x5C06;&#x7528;&#x6237;&#x5BFC;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x4E8B;&#x5148;&#x6307;&#x5B9A;&#x7684;&quot;&#x91CD;&#x5B9A;&#x5411;URI&quot;&#xFF08;redirection URI&#xFF09;&#xFF0C;&#x540C;&#x65F6;&#x9644;&#x4E0A;&#x4E00;&#x4E2A;&#x6388;&#x6743;&#x7801;</li>
<li>D &#x5BA2;&#x6237;&#x7AEF;&#x6536;&#x5230;&#x6388;&#x6743;&#x7801;&#xFF0C;&#x9644;&#x4E0A;&#x65E9;&#x5148;&#x7684;&quot;&#x91CD;&#x5B9A;&#x5411;URI&quot;&#xFF0C;&#x5411;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x7533;&#x8BF7;&#x4EE4;&#x724C;&#x3002;&#x8FD9;&#x4E00;&#x6B65;&#x662F;&#x5728;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x540E;&#x53F0;&#x7684;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x5B8C;&#x6210;&#x7684;&#xFF0C;&#x5BF9;&#x7528;&#x6237;&#x4E0D;&#x53EF;&#x89C1;</li>
<li>E &#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x6838;&#x5BF9;&#x4E86;&#x6388;&#x6743;&#x7801;&#x548C;&#x91CD;&#x5B9A;&#x5411;URI&#xFF0C;&#x786E;&#x8BA4;&#x65E0;&#x8BEF;&#x540E;&#xFF0C;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x9001;&#x8BBF;&#x95EE;&#x4EE4;&#x724C;&#xFF08;access token&#xFF09;&#x548C;&#x66F4;&#x65B0;&#x4EE4;&#x724C;&#xFF08;refresh token&#xFF09;</li>
</ul>
<h3 id="t65.2 &#x7B80;&#x5316;&#x6A21;&#x5F0F;">5.2 &#x7B80;&#x5316;&#x6A21;&#x5F0F; <a href="#t65.2 &#x7B80;&#x5316;&#x6A21;&#x5F0F;"> # </a></h3>
<p>&#x7B80;&#x5316;&#x6A21;&#x5F0F;&#xFF08;implicit grant type&#xFF09;&#x4E0D;&#x901A;&#x8FC7;&#x7B2C;&#x4E09;&#x65B9;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x76F4;&#x63A5;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x5411;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x7533;&#x8BF7;&#x4EE4;&#x724C;&#xFF0C;&#x8DF3;&#x8FC7;&#x4E86;&quot;&#x6388;&#x6743;&#x7801;&quot;&#x8FD9;&#x4E2A;&#x6B65;&#x9AA4;&#xFF0C;&#x56E0;&#x6B64;&#x5F97;&#x540D;&#x3002;&#x6240;&#x6709;&#x6B65;&#x9AA4;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x5B8C;&#x6210;&#xFF0C;&#x4EE4;&#x724C;&#x5BF9;&#x8BBF;&#x95EE;&#x8005;&#x662F;&#x53EF;&#x89C1;&#x7684;&#xFF0C;&#x4E14;&#x5BA2;&#x6237;&#x7AEF;&#x4E0D;&#x9700;&#x8981;&#x8BA4;&#x8BC1;&#x3002;</p>
<p><img src="http://img.zhufengpeixun.cn/implicitgranttype.png" alt="implicitgranttype"></p>
<p>&#x5B83;&#x7684;&#x6B65;&#x9AA4;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>A &#x5BA2;&#x6237;&#x7AEF;&#x5C06;&#x7528;&#x6237;&#x5BFC;&#x5411;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x3002;</li>
<li>B &#x7528;&#x6237;&#x51B3;&#x5B9A;&#x662F;&#x5426;&#x7ED9;&#x4E8E;&#x5BA2;&#x6237;&#x7AEF;&#x6388;&#x6743;&#x3002;</li>
<li>C &#x5047;&#x8BBE;&#x7528;&#x6237;&#x7ED9;&#x4E88;&#x6388;&#x6743;&#xFF0C;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x5C06;&#x7528;&#x6237;&#x5BFC;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x6307;&#x5B9A;&#x7684;&quot;&#x91CD;&#x5B9A;&#x5411;URI&quot;&#xFF0C;&#x5E76;&#x5728;URI&#x7684;Hash&#x90E8;&#x5206;&#x5305;&#x542B;&#x4E86;</li>
<li>D &#x6D4F;&#x89C8;&#x5668;&#x5411;&#x8D44;&#x6E90;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x51FA;&#x8BF7;&#x6C42;&#xFF0C;&#x5176;&#x4E2D;&#x4E0D;&#x5305;&#x62EC;&#x4E0A;&#x4E00;&#x6B65;&#x6536;&#x5230;&#x7684;Hash&#x503C;&#x3002;</li>
<li>E &#x8D44;&#x6E90;&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x7F51;&#x9875;&#xFF0C;&#x5176;&#x4E2D;&#x5305;&#x542B;&#x7684;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;Hash&#x503C;&#x4E2D;&#x7684;&#x4EE4;&#x724C;&#x3002;</li>
<li>F &#x6D4F;&#x89C8;&#x5668;&#x6267;&#x884C;&#x4E0A;&#x4E00;&#x6B65;&#x83B7;&#x5F97;&#x7684;&#x811A;&#x672C;&#xFF0C;&#x63D0;&#x53D6;&#x51FA;&#x4EE4;&#x724C;&#x3002;</li>
<li>G &#x6D4F;&#x89C8;&#x5668;&#x5C06;&#x4EE4;&#x724C;&#x53D1;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</li>
</ul>
<h3 id="t75.3 &#x5BC6;&#x7801;&#x6A21;&#x5F0F;">5.3 &#x5BC6;&#x7801;&#x6A21;&#x5F0F; <a href="#t75.3 &#x5BC6;&#x7801;&#x6A21;&#x5F0F;"> # </a></h3>
<ul>
<li>&#x5BC6;&#x7801;&#x6A21;&#x5F0F;&#xFF08;Resource Owner Password Credentials Grant&#xFF09;&#x4E2D;&#xFF0C;&#x7528;&#x6237;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x63D0;&#x4F9B;&#x81EA;&#x5DF1;&#x7684;&#x7528;&#x6237;&#x540D;&#x548C;&#x5BC6;&#x7801;&#x3002;&#x5BA2;&#x6237;&#x7AEF;&#x4F7F;&#x7528;&#x8FD9;&#x4E9B;&#x4FE1;&#x606F;&#xFF0C;&#x5411;&quot;&#x670D;&#x52A1;&#x5546;&#x63D0;&#x4F9B;&#x5546;&quot;&#x7D22;&#x8981;&#x6388;&#x6743;&#x3002;</li>
<li>&#x5728;&#x8FD9;&#x79CD;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x7528;&#x6237;&#x5FC5;&#x987B;&#x628A;&#x81EA;&#x5DF1;&#x7684;&#x5BC6;&#x7801;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;&#xFF0C;&#x4F46;&#x662F;&#x5BA2;&#x6237;&#x7AEF;&#x4E0D;&#x5F97;&#x50A8;&#x5B58;&#x5BC6;&#x7801;&#x3002;&#x8FD9;&#x901A;&#x5E38;&#x7528;&#x5728;&#x7528;&#x6237;&#x5BF9;&#x5BA2;&#x6237;&#x7AEF;&#x9AD8;&#x5EA6;&#x4FE1;&#x4EFB;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6BD4;&#x5982;&#x5BA2;&#x6237;&#x7AEF;&#x662F;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x4E00;&#x90E8;&#x5206;&#xFF0C;&#x6216;&#x8005;&#x7531;&#x4E00;&#x4E2A;&#x8457;&#x540D;&#x516C;&#x53F8;&#x51FA;&#x54C1;&#x3002;&#x800C;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x53EA;&#x6709;&#x5728;&#x5176;&#x4ED6;&#x6388;&#x6743;&#x6A21;&#x5F0F;&#x65E0;&#x6CD5;&#x6267;&#x884C;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x624D;&#x80FD;&#x8003;&#x8651;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x6A21;&#x5F0F;&#x3002;</li>
</ul>
<p><img src="http://img.zhufengpeixun.cn/password.png" alt="password"></p>
<p>&#x5B83;&#x7684;&#x6B65;&#x9AA4;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>A &#x7528;&#x6237;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x63D0;&#x4F9B;&#x7528;&#x6237;&#x540D;&#x548C;&#x5BC6;&#x7801;&#x3002;</li>
<li>B &#x5BA2;&#x6237;&#x7AEF;&#x5C06;&#x7528;&#x6237;&#x540D;&#x548C;&#x5BC6;&#x7801;&#x53D1;&#x7ED9;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5411;&#x540E;&#x8005;&#x8BF7;&#x6C42;&#x4EE4;&#x724C;&#x3002;</li>
<li>C &#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x786E;&#x8BA4;&#x65E0;&#x8BEF;&#x540E;&#xFF0C;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x63D0;&#x4F9B;&#x8BBF;&#x95EE;&#x4EE4;&#x724C;&#x3002;</li>
</ul>
<h3 id="t85.4 &#x5BA2;&#x6237;&#x7AEF;&#x6A21;&#x5F0F;">5.4 &#x5BA2;&#x6237;&#x7AEF;&#x6A21;&#x5F0F; <a href="#t85.4 &#x5BA2;&#x6237;&#x7AEF;&#x6A21;&#x5F0F;"> # </a></h3>
<ul>
<li>&#x5BA2;&#x6237;&#x7AEF;&#x6A21;&#x5F0F;&#xFF08;Client Credentials Grant&#xFF09;&#x6307;&#x5BA2;&#x6237;&#x7AEF;&#x4EE5;&#x81EA;&#x5DF1;&#x7684;&#x540D;&#x4E49;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4EE5;&#x7528;&#x6237;&#x7684;&#x540D;&#x4E49;&#xFF0C;&#x5411;&quot;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&quot;&#x8FDB;&#x884C;&#x8BA4;&#x8BC1;&#x3002;</li>
<li>&#x4E25;&#x683C;&#x5730;&#x8BF4;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x6A21;&#x5F0F;&#x5E76;&#x4E0D;&#x5C5E;&#x4E8E;OAuth&#x6846;&#x67B6;&#x6240;&#x8981;&#x89E3;&#x51B3;&#x7684;&#x95EE;&#x9898;&#x3002;&#x5728;&#x8FD9;&#x79CD;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x7528;&#x6237;&#x76F4;&#x63A5;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x6CE8;&#x518C;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x4EE5;&#x81EA;&#x5DF1;&#x7684;&#x540D;&#x4E49;&#x8981;&#x6C42;&quot;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&quot;&#x63D0;&#x4F9B;&#x670D;&#x52A1;&#xFF0C;&#x5176;&#x5B9E;&#x4E0D;&#x5B58;&#x5728;&#x6388;&#x6743;&#x95EE;&#x9898;&#x3002;</li>
</ul>
<p><img src="http://img.zhufengpeixun.cn/clientmode.png" alt="clientmode"></p>
<p>&#x5B83;&#x7684;&#x6B65;&#x9AA4;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>A &#x5BA2;&#x6237;&#x7AEF;&#x5411;&#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x8FDB;&#x884C;&#x8EAB;&#x4EFD;&#x8BA4;&#x8BC1;&#xFF0C;&#x5E76;&#x8981;&#x6C42;&#x4E00;&#x4E2A;&#x8BBF;&#x95EE;&#x4EE4;&#x724C;&#x3002;</li>
<li>B &#x8BA4;&#x8BC1;&#x670D;&#x52A1;&#x5668;&#x786E;&#x8BA4;&#x65E0;&#x8BEF;&#x540E;&#xFF0C;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x63D0;&#x4F9B;&#x8BBF;&#x95EE;&#x4EE4;&#x724C;&#x3002;</li>
</ul>
<h2 id="t96. &#x63A5;&#x5165;QQ">6. &#x63A5;&#x5165;QQ <a href="#t96. &#x63A5;&#x5165;QQ"> # </a></h2>
<ul>
<li><a href="http://wiki.connect.qq.com/%E7%BD%91%E7%AB%99%E6%8E%A5%E5%85%A5%E6%B5%81%E7%A8%8B">QQ&#x7F51;&#x7AD9;&#x63A5;&#x5165;&#x6D41;&#x7A0B;</a></li>
<li><a href="http://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token">&#x4F7F;&#x7528;Authorization Code&#x83B7;&#x53D6;Access Token</a></li>
</ul>
<h3 id="t106.1 &#x63A5;&#x5165;&#x6D41;&#x7A0B;">6.1 &#x63A5;&#x5165;&#x6D41;&#x7A0B; <a href="#t106.1 &#x63A5;&#x5165;&#x6D41;&#x7A0B;"> # </a></h3>
<p><img src="http://img.zhufengpeixun.cn/qqflow.jpg" alt="qqflow"></p>
<ol>
<li>&#x5F00;&#x53D1;&#x8005;&#x6CE8;&#x518C;</li>
<li>&#x653E;&#x7F6E;QQ&#x767B;&#x5F55;&#x6309;&#x94AE;</li>
<li>&#x83B7;&#x53D6;Access Token</li>
<li>&#x83B7;&#x53D6;&#x7528;&#x6237;&#x7684;OpenID</li>
<li>&#x8C03;&#x7528;OpenAPI&#x8BBF;&#x95EE;&#x4FEE;&#x6539;&#x7528;&#x6237;&#x4FE1;&#x606F;</li>
</ol>
<h3 id="t116.2 QQ&#x5F00;&#x53D1;&#x5E73;&#x53F0;&#x7684;&#x524D;&#x7F6E;&#x6761;&#x4EF6;">6.2 QQ&#x5F00;&#x53D1;&#x5E73;&#x53F0;&#x7684;&#x524D;&#x7F6E;&#x6761;&#x4EF6; <a href="#t116.2 QQ&#x5F00;&#x53D1;&#x5E73;&#x53F0;&#x7684;&#x524D;&#x7F6E;&#x6761;&#x4EF6;"> # </a></h3>
<ul>
<li>QQ</li>
<li>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x57DF;&#x540D;&#x8BBF;&#x95EE;&#x7684;&#x670D;&#x52A1;&#x5668;</li>
<li>&#x5173;&#x4E8E;&#x5907;&#x6848;</li>
<li>&#x670D;&#x52A1;&#x5668;&#x57DF;&#x540D;&#x73AF;&#x5883;</li>
</ul>
<h3 id="t126.3 &#x5B89;&#x88C5;&#x670D;&#x52A1;&#x5668;">6.3 &#x5B89;&#x88C5;&#x670D;&#x52A1;&#x5668; <a href="#t126.3 &#x5B89;&#x88C5;&#x670D;&#x52A1;&#x5668;"> # </a></h3>
<pre><code class="lang-js">apt update
apt upgrade
wget -qO- https:<span class="hljs-comment">//raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash</span>
source  /root/.bashrc
nvm install stable
npm install pm2 -g
apt install nginx
</code></pre>
<h3 id="t136.4 &#x6DFB;&#x52A0;&#x5E94;&#x7528;">6.4 &#x6DFB;&#x52A0;&#x5E94;&#x7528; <a href="#t136.4 &#x6DFB;&#x52A0;&#x5E94;&#x7528;"> # </a></h3>
<ul>
<li>&#x57DF;&#x540D;   <a href="http://front.zhufengpeixun.cn">http://front.zhufengpeixun.cn</a></li>
<li>&#x56DE;&#x8C03;&#x5730;&#x5740; <a href="http://front.zhufengpeixun.cn/user/callback">http://front.zhufengpeixun.cn/user/callback</a></li>
<li>&#x7F51;&#x7AD9;&#x540D;&#x79F0; &#x73E0;&#x5CF0;&#x524D;&#x7AEF;&#x7CBE;&#x534E;</li>
<li>&#x7F51;&#x7AD9;&#x5907;&#x6848;&#x53F7; </li>
<li>&#x7F51;&#x7AD9;&#x56FE;&#x6807; </li>
</ul>
<h3 id="t146.5 &#x7F16;&#x5199;&#x5E94;&#x7528;">6.5 &#x7F16;&#x5199;&#x5E94;&#x7528; <a href="#t146.5 &#x7F16;&#x5199;&#x5E94;&#x7528;"> # </a></h3>
<h4 id="t156.5.1 QQ&#x8FDE;&#x63A5;">6.5.1 QQ&#x8FDE;&#x63A5; <a href="#t156.5.1 QQ&#x8FDE;&#x63A5;"> # </a></h4>
<pre><code class="lang-js">https:<span class="hljs-comment">//graph.qq.com/oauth2.0/authorize?response_type=code&amp;client_id=101499238&amp;redirect_uri=http%3A%2F%2Ffront.zhufengpeixun.cn%2Fuser%2Fcallback&amp;scope=get_user_info&quot;</span>
</code></pre>
<h4 id="t166.5.2 &#x83B7;&#x53D6;&#x6570;&#x636E;&#x6D41;&#x7A0B;">6.5.2 &#x83B7;&#x53D6;&#x6570;&#x636E;&#x6D41;&#x7A0B; <a href="#t166.5.2 &#x83B7;&#x53D6;&#x6570;&#x636E;&#x6D41;&#x7A0B;"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> client_id=<span class="hljs-string">&apos;101499238&apos;</span>;
<span class="hljs-keyword">const</span> client_secret=<span class="hljs-string">&quot;1af7ef89da1cbb3dae41465a1865a523&quot;</span>;
<span class="hljs-keyword">const</span> redirect_uri=<span class="hljs-string">&apos;http://front.zhufengpeixun.cn/user/callback&apos;</span>;
<span class="hljs-keyword">const</span> code=<span class="hljs-string">&apos;57C038D3AD7C5588570FF8F723EB57DE&apos;</span>;
<span class="hljs-keyword">const</span> request = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;then-jsonp&apos;</span>);
<span class="hljs-keyword">const</span> axios=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;axios&apos;</span>);
<span class="hljs-keyword">const</span> querystring=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;querystring&apos;</span>);
<span class="hljs-keyword">const</span> access_token=<span class="hljs-string">&apos;0CF4BD6B1BA83606E20218E6BA16FF4A&apos;</span>;
<span class="hljs-keyword">const</span> refresh_token=<span class="hljs-string">&apos;7E3C2110B9813BF714BA212094699F7F&apos;</span>;
<span class="hljs-keyword">const</span> openid=<span class="hljs-string">&apos;0E302B779D8D4C72D21E3172C015682B&apos;</span>;
<span class="hljs-keyword">const</span> options={
    <span class="hljs-attr">grant_type</span>: <span class="hljs-string">&apos;authorization_code&apos;</span>,
    client_id,
    client_secret,
    code,
    redirect_uri
}
<span class="hljs-keyword">const</span> query=querystring.stringify(options);

 (<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> response=<span class="hljs-keyword">await</span> axios.get(<span class="hljs-string">`https://graph.qq.com/oauth2.0/token?<span class="hljs-subst">${query}</span>`</span>);
    <span class="hljs-keyword">const</span> data=response.data;
    <span class="hljs-keyword">const</span> result=querystring.parse(data);
    <span class="hljs-keyword">return</span> result;
})().then(<span class="hljs-function"><span class="hljs-params">ret</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(ret)); 

(<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> response=<span class="hljs-keyword">await</span> request(<span class="hljs-string">&apos;GET&apos;</span>,<span class="hljs-string">`https://graph.qq.com/oauth2.0/me?access_token=<span class="hljs-subst">${access_token}</span>`</span>,{<span class="hljs-attr">callbackName</span>:<span class="hljs-string">&quot;callback&quot;</span>});
    <span class="hljs-keyword">return</span> response;
})().then(<span class="hljs-function"><span class="hljs-params">ret</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(ret));

(<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> options={
        <span class="hljs-attr">grant_type</span>: <span class="hljs-string">&apos;refresh_token&apos;</span>,
        client_id,
        client_secret,
        refresh_token
    }
    <span class="hljs-keyword">const</span> query=querystring.stringify(options);
    <span class="hljs-keyword">const</span> response=<span class="hljs-keyword">await</span> axios.get(<span class="hljs-string">`https://graph.qq.com/oauth2.0/token?<span class="hljs-subst">${query}</span>`</span>);
    <span class="hljs-keyword">const</span> data=response.data;
    <span class="hljs-keyword">const</span> result=querystring.parse(data);
    <span class="hljs-keyword">return</span> result;
})().then(<span class="hljs-function"><span class="hljs-params">ret</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(ret)); 

(<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> options={
        access_token,
        <span class="hljs-attr">oauth_consumer_key</span>:client_id,
        openid
    }
    <span class="hljs-keyword">const</span> query=querystring.stringify(options);
    <span class="hljs-keyword">const</span> response=<span class="hljs-keyword">await</span> axios.get(<span class="hljs-string">`https://graph.qq.com/user/get_user_info?<span class="hljs-subst">${query}</span>`</span>);
    <span class="hljs-keyword">const</span> data=response.data;
    <span class="hljs-keyword">return</span> data;
})().then(<span class="hljs-function"><span class="hljs-params">ret</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(ret));
</code></pre>
<ul>
<li><a href="https://gitee.com/zhufengpeixun/qq-client">qq-client</a></li>
</ul>
<h2 id="t177.&#x5F00;&#x53D1;&#x81EA;&#x5DF1;&#x7684;Oauth&#x7CFB;&#x7EDF;">7.&#x5F00;&#x53D1;&#x81EA;&#x5DF1;&#x7684;Oauth&#x7CFB;&#x7EDF; <a href="#t177.&#x5F00;&#x53D1;&#x81EA;&#x5DF1;&#x7684;Oauth&#x7CFB;&#x7EDF;"> # </a></h2>
<h3 id="t187.1 &#x5F00;&#x53D1;&#x5BA2;&#x6237;&#x7AEF;">7.1 &#x5F00;&#x53D1;&#x5BA2;&#x6237;&#x7AEF; <a href="#t187.1 &#x5F00;&#x53D1;&#x5BA2;&#x6237;&#x7AEF;"> # </a></h3>
<p><a href="https://gitee.com/zhufengpeixun/auth-client">auth-client</a></p>
<h4 id="t197.1.1 config.js">7.1.1 config.js <a href="#t197.1.1 config.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports={
    <span class="hljs-attr">appId</span>: <span class="hljs-string">&apos;38aa47d5-da52-417c-a742-1a341a689fcc&apos;</span>,
    <span class="hljs-attr">appKey</span>: <span class="hljs-string">&apos;e49b9b51-7348-4d1e-be59-7bb3125d9337&apos;</span>,
    <span class="hljs-attr">redirect_uri</span>:<span class="hljs-string">&apos;http://localhost:3000/user/callback&apos;</span>,
    <span class="hljs-attr">fetchAccessTokenUrl</span>: <span class="hljs-string">&apos;http://localhost:4000/oauth2.0/token&apos;</span>,
    <span class="hljs-attr">fetchOpenIdUrl</span>: <span class="hljs-string">&apos;http://localhost:4000/oauth2.0/me&apos;</span>,
    <span class="hljs-attr">getUserInfoUrl</span>:<span class="hljs-string">&apos;http://localhost:4000/user/get_user_info&apos;</span>
}
</code></pre>
<h4 id="t207.1.2 utils.js">7.1.2 utils.js <a href="#t207.1.2 utils.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> {parse,format}=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;url&apos;</span>);
exports.addQueryParamsToUrl=<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">url,options</span>) </span>{
    <span class="hljs-keyword">let</span> {protocol,host,pathname,query}=parse(url,<span class="hljs-literal">true</span>);
    <span class="hljs-built_in">Object</span>.assign(query,options);
    <span class="hljs-keyword">return</span> format({protocol,host,pathname,query});
}
</code></pre>
<h4 id="t217.1.3 model.js">7.1.3 model.js <a href="#t217.1.3 model.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> mongoose=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;mongoose&apos;</span>);
<span class="hljs-comment">//https://github.com/Automattic/mongoose/issues/6880</span>
mongoose.set(<span class="hljs-string">&apos;useFindAndModify&apos;</span>,<span class="hljs-literal">false</span>);
<span class="hljs-keyword">const</span> opts = { <span class="hljs-attr">useNewUrlParser</span>: <span class="hljs-literal">true</span> };
<span class="hljs-keyword">let</span> conn=mongoose.createConnection(<span class="hljs-string">&apos;mongodb://localhost/client&apos;</span>,opts);
<span class="hljs-keyword">let</span> Schema=mongoose.Schema;

<span class="hljs-keyword">let</span> UserSchema=<span class="hljs-keyword">new</span> Schema({
    <span class="hljs-attr">access_token</span>: {<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>},
    <span class="hljs-attr">refresh_token</span>:<span class="hljs-built_in">String</span>,
    <span class="hljs-attr">username</span>: {<span class="hljs-attr">type</span>:<span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>},
    <span class="hljs-attr">avatar</span>:{<span class="hljs-attr">type</span>:<span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>}
});

exports.User=conn.model(<span class="hljs-string">&apos;User&apos;</span>,UserSchema);
</code></pre>
<h4 id="t227.1.4 app.js">7.1.4 app.js <a href="#t227.1.4 app.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> express=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;express&apos;</span>);
<span class="hljs-keyword">const</span> path=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">const</span> session=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;express-session&apos;</span>);
<span class="hljs-keyword">const</span> bodyParser=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;body-parser&apos;</span>);
<span class="hljs-keyword">const</span> app=express();
<span class="hljs-keyword">const</span> logger=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;morgan&apos;</span>);
<span class="hljs-keyword">const</span> oauth=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./routes/oauth2&apos;</span>);
<span class="hljs-keyword">const</span> user=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./routes/user&apos;</span>);
app.set(<span class="hljs-string">&apos;view engine&apos;</span>,<span class="hljs-string">&apos;html&apos;</span>);
app.set(<span class="hljs-string">&apos;views&apos;</span>,path.resolve(__dirname,<span class="hljs-string">&apos;views&apos;</span>));
app.engine(<span class="hljs-string">&apos;html&apos;</span>,<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;ejs&apos;</span>).__express);

app.use(bodyParser.urlencoded({<span class="hljs-attr">extends</span>: <span class="hljs-literal">true</span>}));
app.use(logger(<span class="hljs-string">&apos;dev&apos;</span>));
app.use(session({
    <span class="hljs-attr">secret</span>: <span class="hljs-string">&apos;zfpx&apos;</span>,
    <span class="hljs-attr">saveUninitialized</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">resave</span>:<span class="hljs-literal">true</span>
}));
app.use(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res,next</span>) </span>{
    res.createError=<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">status,message</span>) </span>{
        <span class="hljs-keyword">let</span> error=<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(message);
        error.code=<span class="hljs-number">1</span>;
        error.status=status;
        error.message=message;
        <span class="hljs-keyword">return</span> error;
    }
    req.session.user={
        <span class="hljs-string">&quot;_id&quot;</span>: <span class="hljs-string">&quot;5b7f6f189d384c73a7ee9038&quot;</span>,
        <span class="hljs-string">&quot;username&quot;</span>: <span class="hljs-string">&quot;zhangsan&quot;</span>,
        <span class="hljs-string">&quot;password&quot;</span>: <span class="hljs-string">&quot;4&quot;</span>,
        <span class="hljs-string">&quot;avatar&quot;</span>:<span class="hljs-string">&quot;http://www.gravatar.com/avatar/93e9084aa289b7f1f5e4ab6716a56c3b&quot;</span>
    };
    next();
});
app.use(<span class="hljs-string">&apos;/oauth2.0&apos;</span>,oauth);
app.use(<span class="hljs-string">&apos;/user&apos;</span>,user);
app.use(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err,req,res,next</span>) </span>{
    res.status(err.status||<span class="hljs-number">500</span>).json({<span class="hljs-attr">code</span>:err.code,<span class="hljs-attr">message</span>:err.message});
});
app.listen(<span class="hljs-number">4000</span>,() =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`&#x670D;&#x52A1;&#x5DF2;&#x7ECF;&#x5728;4000&#x7AEF;&#x53E3;&#x4E0A;&#x542F;&#x52A8;`</span>);
});
</code></pre>
<h4 id="t237.1.5 user.js">7.1.5 user.js <a href="#t237.1.5 user.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> express=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;express&apos;</span>);
<span class="hljs-keyword">const</span> axios=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;axios&apos;</span>);
<span class="hljs-keyword">const</span> {User}=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../model&apos;</span>);
<span class="hljs-keyword">const</span> querystring = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;querystring&apos;</span>);
<span class="hljs-keyword">const</span> {appId,appKey,redirect_uri,fetchAccessTokenUrl,fetchOpenIdUrl,getUserInfoUrl}=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../config&apos;</span>);
<span class="hljs-keyword">const</span> {addQueryParamsToUrl}=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../utils&apos;</span>);
<span class="hljs-keyword">let</span> router=express.Router();
router.get(<span class="hljs-string">&apos;/login&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res</span>) </span>{
    res.render(<span class="hljs-string">&apos;login&apos;</span>);
});
router.get(<span class="hljs-string">&apos;/callback&apos;</span>,<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res</span>) </span>{
    <span class="hljs-keyword">let</span> {code}=req.query;
    <span class="hljs-keyword">let</span> options={
        <span class="hljs-attr">grant_type</span>: <span class="hljs-string">&apos;authorization_code&apos;</span>,
        <span class="hljs-attr">client_id</span>: appId,
        <span class="hljs-attr">client_secret</span>: appKey,
        code,
        redirect_uri
    }
    <span class="hljs-keyword">let</span> url=addQueryParamsToUrl(fetchAccessTokenUrl,options);
    <span class="hljs-keyword">let</span> result=<span class="hljs-keyword">await</span> axios.get(url);
    <span class="hljs-keyword">let</span> {access_token,expires_in,refresh_token}=querystring.parse(result.data);

    url=addQueryParamsToUrl(fetchOpenIdUrl,{
        access_token
    });
    result=<span class="hljs-keyword">await</span> axios.get(url);
    <span class="hljs-keyword">let</span> start=result.data.indexOf(<span class="hljs-string">&apos;{&apos;</span>);
    <span class="hljs-keyword">let</span> end=result.data.lastIndexOf(<span class="hljs-string">&apos;}&apos;</span>);
    result.data=result.data.slice(start,end+<span class="hljs-number">1</span>);
    <span class="hljs-keyword">let</span> {client_id,openid}=<span class="hljs-built_in">JSON</span>.parse(result.data);
    url=addQueryParamsToUrl(getUserInfoUrl,{
        access_token,
        <span class="hljs-attr">oauth_consumer_key</span>: client_id,
        openid
    });
    result=<span class="hljs-keyword">await</span> axios.get(url);
    <span class="hljs-keyword">let</span> {username,avatar}=result.data;
    <span class="hljs-keyword">let</span> user = <span class="hljs-keyword">await</span> User.create({
        access_token,
        refresh_token,
        username,
        avatar
    });
    req.session.user=user;
    res.redirect(<span class="hljs-string">&apos;/&apos;</span>);
});
<span class="hljs-built_in">module</span>.exports=router;
</code></pre>
<h4 id="t247.1.6 login.html">7.1.6 login.html <a href="#t247.1.6 login.html"> # </a></h4>
<pre><code class="lang-js">&lt;%include header.html%&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;row&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-12&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;http://localhost:4000/oauth2.0/authorize?response_type=code&amp;client_id=5b7f704beacb0274b068da17&amp;redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fuser%2Fcallback&amp;scope=list_album,get_user_info&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;/images/qq.png&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%include</span> <span class="hljs-attr">footer.html</span>%&gt;</span>
</span></code></pre>
<h4 id="t257.1.7 index.html">7.1.7 index.html <a href="#t257.1.7 index.html"> # </a></h4>
<pre><code class="lang-js">&lt;%include header.html%&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;row&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-12&quot;</span>&gt;</span>
        &#x4F60;&#x5DF2;&#x7ECF;&#x767B;&#x5F55;&#xFF0C;&#x6B22;&#x8FCE;&#x4F60; <span class="hljs-tag">&lt;<span class="hljs-name">%=user.username%</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;&lt;%=user.avatar%&gt;&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%include</span> <span class="hljs-attr">footer.html</span>%&gt;</span>
</span></code></pre>
<h3 id="t267.2 &#x5F00;&#x53D1;&#x6388;&#x6743;&#x670D;&#x52A1;&#x5668;">7.2 &#x5F00;&#x53D1;&#x6388;&#x6743;&#x670D;&#x52A1;&#x5668; <a href="#t267.2 &#x5F00;&#x53D1;&#x6388;&#x6743;&#x670D;&#x52A1;&#x5668;"> # </a></h3>
<p><a href="https://gitee.com/zhufengpeixun/auth-server">auth-server</a></p>
<h4 id="t277.2.1 model.js">7.2.1 model.js <a href="#t277.2.1 model.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> mongoose=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;mongoose&apos;</span>);
<span class="hljs-comment">//https://github.com/Automattic/mongoose/issues/6880</span>
mongoose.set(<span class="hljs-string">&apos;useFindAndModify&apos;</span>,<span class="hljs-literal">false</span>);
<span class="hljs-keyword">const</span> opts = { <span class="hljs-attr">useNewUrlParser</span>: <span class="hljs-literal">true</span> };
<span class="hljs-keyword">let</span> conn=mongoose.createConnection(<span class="hljs-string">&apos;mongodb://localhost/oauth&apos;</span>,opts);
<span class="hljs-keyword">let</span> Schema=mongoose.Schema;
<span class="hljs-keyword">let</span> ObjectId=Schema.Types.ObjectId;
<span class="hljs-keyword">let</span> ApplicationSchema=<span class="hljs-keyword">new</span> Schema({
    <span class="hljs-attr">appId</span>: {<span class="hljs-attr">type</span>:<span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>}, <span class="hljs-comment">//appId</span>
    appKey: {<span class="hljs-attr">type</span>:<span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>}, <span class="hljs-comment">//appKey</span>
    website: {<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>}, <span class="hljs-comment">//&#x7F51;&#x7AD9;&#x540D;&#x79F0;</span>
    redirect_uri: {<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>}<span class="hljs-comment">//&#x56DE;&#x8C03;&#x5730;&#x5740;</span>
});

exports.Application=conn.model(<span class="hljs-string">&apos;Application&apos;</span>,ApplicationSchema);

<span class="hljs-keyword">let</span> UserSchema=<span class="hljs-keyword">new</span> Schema({
    <span class="hljs-attr">username</span>: {<span class="hljs-attr">type</span>:<span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>}, <span class="hljs-comment">//appId</span>
    password: {<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>}, <span class="hljs-comment">//appKey</span>
    avatar:{<span class="hljs-attr">type</span>:<span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>}
});

exports.User=conn.model(<span class="hljs-string">&apos;User&apos;</span>,UserSchema);

<span class="hljs-keyword">let</span> AuthorizationCodeSchema=<span class="hljs-keyword">new</span> Schema({
    <span class="hljs-attr">client_id</span>: {<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>}, 
    <span class="hljs-attr">user</span>: {<span class="hljs-attr">type</span>: ObjectId,<span class="hljs-attr">ref</span>: <span class="hljs-string">&apos;User&apos;</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>}, 
    <span class="hljs-attr">permissions</span>: {<span class="hljs-attr">type</span>: [{<span class="hljs-attr">type</span>:ObjectId,<span class="hljs-attr">ref</span>:<span class="hljs-string">&apos;Permission&apos;</span>}],<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>},
    <span class="hljs-attr">createAt</span>:{<span class="hljs-attr">type</span>:<span class="hljs-built_in">Date</span>,<span class="hljs-attr">default</span>:<span class="hljs-built_in">Date</span>.now}<span class="hljs-comment">//10&#x5206;&#x949F;&#x5185;&#x8FC7;&#x671F;</span>
});

exports.AuthorizationCode=conn.model(<span class="hljs-string">&apos;AuthorizationCode&apos;</span>,AuthorizationCodeSchema);

<span class="hljs-keyword">let</span> PermissionSchema=<span class="hljs-keyword">new</span> Schema({
    <span class="hljs-attr">name</span>: {<span class="hljs-attr">type</span>:<span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>}, 
    <span class="hljs-attr">scope</span>: {<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>}
});

exports.Permission=conn.model(<span class="hljs-string">&apos;Permission&apos;</span>,PermissionSchema);

<span class="hljs-keyword">let</span> AccessTokenSchema=<span class="hljs-keyword">new</span> Schema({
    <span class="hljs-attr">client_id</span>: {<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>}, 
    <span class="hljs-attr">user</span>: {<span class="hljs-attr">type</span>: ObjectId,<span class="hljs-attr">ref</span>: <span class="hljs-string">&apos;User&apos;</span>,<span class="hljs-attr">required</span>:<span class="hljs-literal">true</span>}, 
    <span class="hljs-attr">permissions</span>: {<span class="hljs-attr">type</span>: [{<span class="hljs-attr">type</span>: ObjectId,<span class="hljs-attr">ref</span>: <span class="hljs-string">&apos;Permission&apos;</span>}],<span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>},
    <span class="hljs-attr">refresh_token</span>:{<span class="hljs-attr">type</span>:<span class="hljs-built_in">String</span>},
    <span class="hljs-attr">createAt</span>:{<span class="hljs-attr">type</span>:<span class="hljs-built_in">Date</span>,<span class="hljs-attr">default</span>:<span class="hljs-built_in">Date</span>.now}<span class="hljs-comment">//10&#x5206;&#x949F;&#x5185;&#x8FC7;&#x671F;</span>
});

exports.AccessToken=conn.model(<span class="hljs-string">&apos;AccessToken&apos;</span>,AccessTokenSchema);
</code></pre>
<h4 id="t287.2.2 mock.js">7.2.2 mock.js <a href="#t287.2.2 mock.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> uuid=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;uuid&apos;</span>);
<span class="hljs-keyword">let</span> {Application,User,AuthorizationCode,Permission}=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./model&apos;</span>);

<span class="hljs-comment">/* User.create({username: &apos;zhangsan&apos;,password: &apos;4&apos;},(err,doc) =&gt; {
    console.log(doc);
}); */</span>

<span class="hljs-keyword">let</span> appId=uuid.v4();<span class="hljs-comment">// 38aa47d5-da52-417c-a742-1a341a689fcc</span>
<span class="hljs-keyword">let</span> appKey=uuid.v4();<span class="hljs-comment">// e49b9b51-7348-4d1e-be59-7bb3125d9337</span>
<span class="hljs-keyword">let</span> redirect_uri=<span class="hljs-string">&apos;http://localhost:3000/user/callback&apos;</span>;
<span class="hljs-keyword">let</span> encode_redirect_uri=<span class="hljs-built_in">encodeURIComponent</span>(redirect_uri);
<span class="hljs-built_in">console</span>.log(encode_redirect_uri);
<span class="hljs-comment">//let name=&apos;&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;&apos;;</span>
<span class="hljs-comment">/* Application.create({appId,appKey,redirect_uri,name},(err,doc) =&gt; {
    console.log(doc);
}); */</span>

<span class="hljs-comment">//let name=&apos;&#x83B7;&#x5F97;&#x60A8;&#x7684;&#x6635;&#x79F0;&#x3001;&#x5934;&#x50CF;&#x3001;&#x6027;&#x522B;&apos;;</span>
<span class="hljs-keyword">let</span> name=<span class="hljs-string">&quot;&#x83B7;&#x53D6;&#x767B;&#x5F55;&#x7528;&#x6237;&#x7684;&#x76F8;&#x518C;&#x5217;&#x8868;&quot;</span>;
<span class="hljs-comment">//let scope=&apos;get_user_info&apos;;//</span>
<span class="hljs-keyword">let</span> scope=<span class="hljs-string">&apos;list_album&apos;</span>;
<span class="hljs-comment">/* Permission.create({name,scope},(err,doc) =&gt; {
    console.log(doc);
}); */</span>
</code></pre>
<h4 id="t297.2.3 app.js">7.2.3 app.js <a href="#t297.2.3 app.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> express=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;express&apos;</span>);
<span class="hljs-keyword">const</span> path=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">const</span> session=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;express-session&apos;</span>);
<span class="hljs-keyword">const</span> bodyParser=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;body-parser&apos;</span>);
<span class="hljs-keyword">const</span> app=express();
<span class="hljs-keyword">const</span> logger=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;morgan&apos;</span>);
<span class="hljs-keyword">const</span> oauth=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./routes/oauth2&apos;</span>);
<span class="hljs-keyword">const</span> user=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./routes/user&apos;</span>);
app.set(<span class="hljs-string">&apos;view engine&apos;</span>,<span class="hljs-string">&apos;html&apos;</span>);
app.set(<span class="hljs-string">&apos;views&apos;</span>,path.resolve(__dirname,<span class="hljs-string">&apos;views&apos;</span>));
app.engine(<span class="hljs-string">&apos;html&apos;</span>,<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;ejs&apos;</span>).__express);

app.use(bodyParser.urlencoded({<span class="hljs-attr">extends</span>: <span class="hljs-literal">true</span>}));
app.use(logger(<span class="hljs-string">&apos;dev&apos;</span>));
app.use(session({
    <span class="hljs-attr">secret</span>: <span class="hljs-string">&apos;zfpx&apos;</span>,
    <span class="hljs-attr">saveUninitialized</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">resave</span>:<span class="hljs-literal">true</span>
}));
app.use(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res,next</span>) </span>{
    res.createError=<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">status,message</span>) </span>{
        <span class="hljs-keyword">let</span> error=<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(message);
        error.code=<span class="hljs-number">1</span>;
        error.status=status;
        error.message=message;
        <span class="hljs-keyword">return</span> error;
    }
    req.session.user={
        <span class="hljs-string">&quot;_id&quot;</span>: <span class="hljs-string">&quot;5b7f6f189d384c73a7ee9038&quot;</span>,
        <span class="hljs-string">&quot;username&quot;</span>: <span class="hljs-string">&quot;zhangsan&quot;</span>,
        <span class="hljs-string">&quot;password&quot;</span>: <span class="hljs-string">&quot;4&quot;</span>,
        <span class="hljs-string">&quot;avatar&quot;</span>:<span class="hljs-string">&quot;http://www.gravatar.com/avatar/93e9084aa289b7f1f5e4ab6716a56c3b&quot;</span>
    };
    next();
});
app.use(<span class="hljs-string">&apos;/oauth2.0&apos;</span>,oauth);
app.use(<span class="hljs-string">&apos;/user&apos;</span>,user);
app.use(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err,req,res,next</span>) </span>{
    res.status(err.status||<span class="hljs-number">500</span>).json({<span class="hljs-attr">code</span>:err.code,<span class="hljs-attr">message</span>:err.message});
});
app.listen(<span class="hljs-number">4000</span>,() =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`&#x670D;&#x52A1;&#x5DF2;&#x7ECF;&#x5728;4000&#x7AEF;&#x53E3;&#x4E0A;&#x542F;&#x52A8;`</span>);
});
</code></pre>
<h4 id="t307.2.4 oauth2.js">7.2.4 oauth2.js <a href="#t307.2.4 oauth2.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> express=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;express&apos;</span>);
<span class="hljs-keyword">let</span> uuid=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;uuid&apos;</span>);
<span class="hljs-keyword">const</span> querystring=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;querystring&apos;</span>);
<span class="hljs-keyword">const</span> {Application,Permission,AuthorizationCode,AccessToken}=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../model&apos;</span>);
<span class="hljs-keyword">let</span> router=express.Router();
router.get(<span class="hljs-string">&apos;/authorize&apos;</span>,<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res,next</span>) </span>{
    <span class="hljs-comment">//http://localhost:4000/oauth2.0/authorize?response_type=code&amp;client_id=5b7f704beacb0274b068da17&amp;redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fuser%2Fcallback</span>
    <span class="hljs-keyword">let</span> {response_type=<span class="hljs-string">&apos;code&apos;</span>,client_id,redirect_uri,scope=<span class="hljs-string">&apos;get_user_info&apos;</span>}=req.query;
    <span class="hljs-keyword">if</span> (!client_id) {
        <span class="hljs-keyword">return</span> next(res.createError(<span class="hljs-number">400</span>,<span class="hljs-string">&apos;&#x7F3A;&#x5C11; client_id &#x53C2;&#x6570;&apos;</span>));
    }
    <span class="hljs-keyword">if</span> (!redirect_uri) {
        <span class="hljs-keyword">return</span> next(res.createError(<span class="hljs-number">400</span>,<span class="hljs-string">&apos;&#x7F3A;&#x5C11; redirect_uri &#x53C2;&#x6570;&apos;</span>));
    }
    redirect_uri=<span class="hljs-built_in">decodeURIComponent</span>(redirect_uri);
    <span class="hljs-keyword">let</span> client=<span class="hljs-keyword">await</span> Application.findById(client_id);
    <span class="hljs-keyword">if</span> (client.redirect_uri !== redirect_uri) {
        <span class="hljs-keyword">return</span> next(res.createError(<span class="hljs-number">400</span>,<span class="hljs-string">&apos;&#x4F20;&#x5165;&#x7684;&#x56DE;&#x8C03;&#x5730;&#x5740;&#x4E0D;&#x5339;&#x914D;&apos;</span>));
    }
    <span class="hljs-keyword">let</span> query={<span class="hljs-attr">$or</span>: scope.split(<span class="hljs-string">&apos;,&apos;</span>).map(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> ({<span class="hljs-attr">scope</span>: item}))};
    <span class="hljs-keyword">let</span> permissions=<span class="hljs-keyword">await</span> Permission.find(query);
    res.render(<span class="hljs-string">&apos;authorize&apos;</span>,{
        <span class="hljs-attr">user</span>:req.session.user,
        client,
        permissions
    });    
});

router.post(<span class="hljs-string">&apos;/authorize&apos;</span>,<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res,next</span>) </span>{
    <span class="hljs-keyword">let</span> {client_id,redirect_uri}=req.query;
    <span class="hljs-keyword">let</span> {permissions}=req.body;
    <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">Array</span>.isArray(permissions)) {
        permissions=[permissions]
    }
    <span class="hljs-keyword">let</span> authorizationCode=<span class="hljs-keyword">await</span> AuthorizationCode.create({
        client_id,
        <span class="hljs-attr">user</span>: req.session.user._id,
        permissions
    });
    res.redirect(<span class="hljs-string">`<span class="hljs-subst">${redirect_uri}</span>?code=<span class="hljs-subst">${authorizationCode._id}</span>`</span>);
});

router.get(<span class="hljs-string">&apos;/token&apos;</span>,<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res,next</span>) </span>{
    <span class="hljs-keyword">let</span> {grant_type,client_id,client_secret,code,redirect_uri}=req.query;
    <span class="hljs-keyword">let</span> authorizationCode=<span class="hljs-keyword">await</span> AuthorizationCode.findById(code);
    <span class="hljs-keyword">if</span> (!authorizationCode) {
        <span class="hljs-keyword">return</span> next(res.createError(<span class="hljs-number">400</span>,<span class="hljs-string">&apos;&#x6388;&#x6743;&#x7801;&#x9519;&#x8BEF;&apos;</span>));
    }
    <span class="hljs-keyword">let</span> accessToken=<span class="hljs-keyword">await</span> AccessToken.create({
        <span class="hljs-attr">client_id</span>: authorizationCode.client_id,
        <span class="hljs-attr">user</span>:authorizationCode.user,
        <span class="hljs-attr">refresh_token</span>: uuid.v4(),
        <span class="hljs-attr">permissions</span>:authorizationCode.permissions
    });
    <span class="hljs-keyword">let</span> result={<span class="hljs-attr">access_token</span>: accessToken._id.toString(),<span class="hljs-attr">expires_in</span>: <span class="hljs-number">60</span>*<span class="hljs-number">60</span>*<span class="hljs-number">24</span>*<span class="hljs-number">90</span>};
    res.send(querystring.stringify(result));
});

router.get(<span class="hljs-string">&apos;/me&apos;</span>,<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res,next</span>) </span>{
    <span class="hljs-keyword">let</span> {access_token}=req.query;
    <span class="hljs-keyword">if</span> (!access_token) {
        <span class="hljs-keyword">return</span> next(res.createError(<span class="hljs-number">400</span>,<span class="hljs-string">&apos;access_token&#x672A;&#x63D0;&#x4F9B;&apos;</span>));
    }
    <span class="hljs-keyword">let</span> {client_id,<span class="hljs-attr">user</span>:openid} = <span class="hljs-keyword">await</span> AccessToken.findById(access_token);
    <span class="hljs-keyword">let</span> result={
        client_id,
        openid
    }
    res.send(<span class="hljs-string">`callback(<span class="hljs-subst">${<span class="hljs-built_in">JSON</span>.stringify(result)}</span>)`</span>);    
});
<span class="hljs-built_in">module</span>.exports=router;
</code></pre>
<h4 id="t317.2.5 routes/users.js">7.2.5 routes/users.js <a href="#t317.2.5 routes/users.js"> # </a></h4>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;express&apos;</span>);
<span class="hljs-keyword">const</span> {User} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../model&apos;</span>);
<span class="hljs-keyword">let</span> router=express.Router();
router.get(<span class="hljs-string">&apos;/get_user_info&apos;</span>,<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req,res</span>) </span>{
    <span class="hljs-keyword">let</span> {access_token,oauth_consumer_key,openid}=req.query;
    <span class="hljs-keyword">let</span> user = <span class="hljs-keyword">await</span> User.findById(openid);
    res.json(user);
});
<span class="hljs-built_in">module</span>.exports=router;
</code></pre>
<h4 id="t327.2.6 authorize.html">7.2.6 authorize.html <a href="#t327.2.6 authorize.html"> # </a></h4>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">%include</span> <span class="hljs-attr">header.html</span>%&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;row&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-12&quot;</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;POST&quot;</span>&gt;</span>
           <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;row&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-6&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;panel panel-default&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;panel-heading&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">h4</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;text-center&quot;</span>&gt;</span>&#x5FEB;&#x901F;&#x767B;&#x5F55;<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;panel-body text-center&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;&lt;%=user.avatar%&gt;&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;display:inline-block&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;img-responsive&quot;</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">&quot;&#x5934;&#x50CF;&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;panel-footer text-center&quot;</span>&gt;</span>
                      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-primary&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x6388;&#x6743;&#x5E76;&#x767B;&#x5F55;&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-6&quot;</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;list-group&quot;</span>&gt;</span>
                 <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;list-group-item&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">%=client.website%</span>&gt;</span>&#x5C06;&#x83B7;&#x5F97;&#x4EE5;&#x4E0B;&#x6743;&#x9650;&#xFF1A;<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                 <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;list-group-item&quot;</span>&gt;</span>
                   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;checkbox&quot;</span>&gt;</span>
                           <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;checkbox&quot;</span>&gt;</span>&#x5168;&#x9009;
                        <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                   <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                   <span class="hljs-tag">&lt;<span class="hljs-name">%permissions.forEach(function(permission){%</span>&gt;</span>
                      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;checkbox&quot;</span>&gt;</span>
                           <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;checkbox&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;permissions&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&lt;%=permission._id%&gt;&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">%=permission.name%</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                   <span class="hljs-tag">&lt;<span class="hljs-name">%})%</span>&gt;</span>
                 <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                 <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;list-group-item&quot;</span>&gt;</span>&#x6388;&#x6743;&#x540E;&#x8868;&#x660E;&#x4F60;&#x5DF2;&#x540C;&#x610F; QQ&#x767B;&#x5F55;&#x670D;&#x52A1;&#x534F;&#x8BAE;<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%include</span> <span class="hljs-attr">footer.html</span>%&gt;</span>
</code></pre>
<h2 id="t338. &#x53C2;&#x8003;&#x8D44;&#x6599;">8. &#x53C2;&#x8003;&#x8D44;&#x6599; <a href="#t338. &#x53C2;&#x8003;&#x8D44;&#x6599;"> # </a></h2>
<ul>
<li><a href="http://www.rfcreader.com/#rfc6749">rfc6749</a></li>
<li><a href="https://connect.qq.com/">QQ&#x4E92;&#x8054;</a></li>
<li><a href="http://wiki.connect.qq.com/%E5%BC%80%E5%8F%91%E6%94%BB%E7%95%A5_server-side#Step2.EF.BC.9A.E8.8E.B7.E5.8F.96AuthorizationCode"> &#x5F00;&#x53D1;&#x653B;&#x7565;_Server-side&#x7684;Step2&#x548C;Step3</a></li>
<li><a href="http://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token">&#x4F7F;&#x7528;Authorization Code&#x83B7;&#x53D6;Access Token</a></li>
<li><a href="http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html">&#x7406;&#x89E3;OAuth 2.0</a></li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
